package com.example.spring.boot.rabbitmq.controller;

import com.example.spring.boot.rabbitmq.constant.FanoutExchangeConstant;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * FanoutExchangeController
 * </p>
 *
 * @author weixin
 * @date 2023/3/28 14:43
 */
@RestController
@RequestMapping("/fanout/")
public class FanoutExchangeController {

    private final RabbitTemplate rabbitTemplate;

    public FanoutExchangeController(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    /**
     * fanout交换机为扇形模式交换机
     *      消息会发送到所有绑定的队列上。
     */
    @GetMapping("sendFanout")
    public Object sendFanout() {
        rabbitTemplate.convertAndSend(FanoutExchangeConstant.FANOUT_EXCHANGE,
                "",
                "发送一条测试消息：fanout");
        return "fanout消息发送成功！！";
    }

}
